//
//  ViewController.m
//  7.22录音动画
//
//  Created by lovena on 15/7/22.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "DSZLYViewController.h"
#import "HomeViewController.h"
@interface DSZLYViewController ()
@property (weak, nonatomic) IBOutlet UIButton *footbtn;
- (IBAction)clickFootBtn;
- (IBAction)returnBtn;
@property (weak, nonatomic) IBOutlet UIView *footView;
@property(nonatomic,strong)UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *resultLabel;
@property(nonatomic,assign)NSInteger time;
@end

@implementation DSZLYViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //按钮圆角设置
    _footbtn.layer.cornerRadius=55;
    _footbtn.layer.masksToBounds=YES;
    
    _resultLabel.alpha=0;
    
    //加载一个图像
    _imageView=[[UIImageView alloc]initWithFrame:self.footView.bounds];
    [self.footView addSubview:_imageView];
    
    [_footbtn bringSubviewToFront:_footView];
    
    [self loadAnimation];
    _footbtn.enabled=NO;
}

-(void)loadAnimation
{
    //_time=-1;
    NSMutableArray *array=[NSMutableArray array];
    for(int i=1;i<19;i++)
    {
        NSString *str=[NSString stringWithFormat:@"animation_%i",i];
        UIImage *image=[UIImage imageNamed:str];
        [array addObject:image];
    }
    
    //动画
    [_imageView setAnimationImages:array];
    [_imageView setAnimationRepeatCount:2];
    [_imageView setAnimationDuration:3];
    [_imageView startAnimating];
    
    //5秒后
    [self performSelector:@selector(resultNext) withObject:nil afterDelay:6];
    
}

//5秒后zhixing
-(void)resultNext
{
    //_time=1;
    [_imageView stopAnimating];
    NSMutableArray *array=[NSMutableArray array];
    for(int i=19;i<26;i++)
    {
        NSString *str=[NSString stringWithFormat:@"animation_%i",i];
        UIImage *image=[UIImage imageNamed:str];
        [array addObject:image];
    }
    
    //动画
    [_imageView setAnimationImages:array];
    [_imageView setAnimationRepeatCount:1];
    [_imageView setAnimationDuration:2];
    [_imageView startAnimating];
    
    [UIView animateWithDuration:4 animations:^{
    
        _resultLabel.alpha=0.4;
        _footbtn.enabled=YES;
        
    }];

}

- (IBAction)clickFootBtn {
    _footbtn.enabled=NO;
        [self loadAnimation];
        [UIView animateWithDuration:1 animations:^{
            
            _resultLabel.alpha=0;
        }];
 

   }

- (IBAction)returnBtn {
//    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//    HomeViewController *home = [story instantiateViewControllerWithIdentifier:@"shouye"];
//    [self.navigationController pushViewController:home animated:YES];
    
//    [self.navigationController popViewControllerAnimated:YES];
    
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end
